#!/usr/bin/env python
#coding=utf-8 


# 静态函数和类函数
class TestStaticMethod:
	@staticmethod
	def foo():
		print 'calling static method foo()'

class TestClassMethod:
	@classmethod
	def foo(cls):
		print 'calling class method foo()'
		print 'foo() is part of calss:', cls.__name__
class P: pass
# super
class C(P):
	def __init__(self):
		super(C, self).__init__() # 不用明确给出基类的名字
		print "calling C's constructor"

# 相当于
class C(P):
	def __init__(self):
		P.__init__(self)
		print "calling C's constructor"


# __mro__ 查找顺序


# issubclass()  判断一个类是否是另一个类的子类
# isinstance() 是否是一个类的实例

# 属性相关函数
class MyClass(object):
	def __init__(self):
		self.foo = 100

myInst = MyClass()
print hasattr(myInst, 'foo')
print getattr(myInst, 'foo')
print getattr(myInst, 'bar', 'oops')
print setattr(myInst, 'bar', 'set')
print dir(myInst)
delattr(myInst, 'foo')
print dir(myInst)

print
print

class C(object): pass
c = C()
c.foo = 100
c.bar = 'python'
print c.__dict__
print vars(c)